import 'package:flutter/material.dart';
import 'package:flutter_duqin/components/root_page_head.dart';
import 'package:flutter_duqin/sub_pages/article_page.dart';
import 'package:flutter_duqin/sub_pages/recommend_page.dart';
import 'package:flutter_duqin/sub_pages/song_page.dart';
import 'package:flutter_duqin/sub_pages/singer_page.dart';
import 'package:flutter_duqin/sub_pages/tiny_video_page.dart';
import 'package:flutter_duqin/sub_pages/video_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

const List<Tab> _tabs = [
  Tab(
    text: '歌曲',
  ),
  Tab(
    text: '推荐',
  ),
  Tab(
    text: '歌手',
  ),
  Tab(
    text: '小视频',
  ),
  Tab(
    text: '文章',
  ),
  Tab(
    text: '视频',
  )
];

const List<Widget> _tabContents = [
  SongPage(),
  RecommendPage(),
  SingerPage(),
  TinyVideoPage(),
  ArticlePage(),
  VideoPage()
];

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();

    _tabController =
        TabController(initialIndex: 1, length: _tabs.length, vsync: this);

    // getList();
  }

  // Future getList() async {
  //   final result = await Http.get('/api/Songs');
  //   print(result);
  // }

  @override
  void dispose() {
    _tabController.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const RootPageHead(),
        bottom: TabBar(
          tabs: _tabs,
          controller: _tabController,
          isScrollable: true,
        ),
      ),
      body: TabBarView(
        children: _tabContents,
        controller: _tabController,
      ),
    );
  }
}
